<?php

namespace app\admin\logic;

use app\admin\model\GgoodsProp;
use think\facade\Db;

class Goodsproplogic
{

    // 留值
    public static function getDataAttribute($param)
    {

        $data = [
            'keywords'=>isset($param['keywords'])?$param['keywords']:'',
            'pval'=>isset($param['pval'])?$param['pval']:[],
        ];

        return $data;
    }

    // pvalues变中文
    public static function getGoodsPropName($sel,$gpv)
    {

        foreach ($sel as &$v){
                $v['pvalues']=explode(',',$v['pvalues']);
                $arr=[];

                foreach ($v['pvalues'] as $vo){
//                    $arr[] = GgoodsProp::getGoodsPropValue($vo);
                    foreach ($gpv as $vvv){
                        if ($vo == $vvv['vid']){
                            $arr[]=$vvv['prop_value'];
                        }
                    }
                }
                $v['pvalues'] = implode(',',$arr);
//                $arr=implode(',',$arr);
//                $v['pvalues']=$arr;

        }
        return $sel;
    }

    // 接值where条件
    public static function getWereAttribute($param)
    {

        $where=[];
        $whereOr=[];
        if (isset($param['keywords']) && !empty($param['keywords'])){
            $where[] = ['pname','like','%'.$param['keywords'].'%'];
        }
        if (isset($param['pval']) && !empty($param['pval'])){

            foreach ($param['pval'] as $v){

                $whereOr[]=['pvalues','find in set',$v];

            }




        }
        return [$where,$whereOr];
    }


}